<template>
	<view class="equipment">
		<u-navbar title="常用设备管理" :autoBack="true" :placeholder="true">
		</u-navbar>

		<view v-if="equipmentList.length>0" class="equipmentList">
			<!-- <view class="equipment_item" v-for="(item,index) in equipmentList" :key="index">
				{{item.devicesName}}
			</view> -->
			<u-swipe-action>
				<u-swipe-action-item :options="options1" v-for="(item,index) in equipmentList" :key="index"
					@click="handleclick">
					<view class="equipment_item">
						<view class="swipe-action__content">
							<text class="swipe-action__content__text">{{item.devicesName}}</text>
						</view>
					</view>
				</u-swipe-action-item>
			</u-swipe-action>
		</view>

		<view v-else class="dataNull">
			<image src="https://mp.blrwworkshop.com/imgs/dataNull.png" mode=""></image>
			<view class="">
				暂无设备
			</view>
		</view>


	</view>
</template>

<script>
	import {
		qryOnlineDevices,
		removeOnlineDevices
	} from "@/api/mine.js"
	export default {
		data() {
			return {
				options1: [{
					text: '删除'
				}],
				equipmentList: []
			}
		},
		onLoad() {
			this.handleGetqryOnlineDevices()
		},
		methods: {
			async handleGetqryOnlineDevices() {
				let res = await qryOnlineDevices()
				if (res.code == 200) {
					this.equipmentList = res.data
				}
			},
			async handleclick(e) {
				// console.log("2222", e)
				let res = await removeOnlineDevices({
					id: this.equipmentList[e.index].id
				})
				if (res.code == 200) {
					uni.showToast({
						title: '删除成功',
						icon: 'none'
					})
					setTimeout(() => {
						this.handleGetqryOnlineDevices()
					}, 1500)
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.equipment {
		width: 100%;
		min-height: 100vh;
		background-color: #F9F9F9;

		.equipmentList {
			width: 100%;

			.equipment_item {
				width: 100%;
				// height: 88rpx;
				// padding: 24rpx 30rpx;
				box-sizing: border-box;
				background-color: #ffffff;
				margin-top: 1rpx;
			}
		}
	}

	.dataNull {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 200rpx;
		font-weight: 400;
		font-size: 28rpx;
		color: #DDDDDD;
		margin-top: 20rpx;

		image {
			width: 330rpx;
			height: 330rpx;

		}
	}

	.u-page {
		padding: 0;
	}

	.u-demo-block__title {
		padding: 10px 0 2px 15px;
	}

	.swipe-action {
		background-color: #DB2727;

		&__content {
			padding: 25rpx 0;

			&__text {
				font-size: 15px;
				padding-left: 30rpx;
			}
		}
	}
</style>